package T0;

/**
 * @Author cheng.song
 * @create 2022/1/26 17:11
 */
public class 搜索插入位置35 {

    public static void main(String[] args) {
        int nums[] = new int[]{1,3,5,6};
        System.out.println(searchInsert(nums,0));
    }

    public static int searchInsert(int[] nums, int target) {
        int left=0;
        int right=nums.length-1;
        while (left<=right){
           int mid = (left+right)/2;
           if(nums[mid]==target)
               return mid;
           if(nums[mid]>target){
               right =mid-1;
           }else if(nums[mid]<target){
               left =mid+1;
           }
        }
        return right+1;
    }

}
